package com.dfbz.dao;

import com.alibaba.excel.util.StringUtils;
import org.apache.ibatis.annotations.Param;

import java.util.Map;

public class ArticleSqlProvider {


    public String articleConditionPage(Map<String, String> map){
        StringBuilder sb = new StringBuilder();
        sb.append("select \n" +
                "id,\n" +
                "title,\n" +
                "content,\n" +
                "browse_count,\n" +
                "publish_date,\n" +
                "publish_real_name,\n" +
                "user_id\n" +
                "from article ");
        if (map.containsKey("value")&& !StringUtils.isEmpty(map.get("value"))){
            sb.append("where title like concat('%',#{value},'%')");
        }

        return sb.toString();
    }

    public String titleByNameLimit(Map<String,Object> map){
        StringBuilder sb = new StringBuilder();

        sb.append("select \n" +
                  "a.id,\n" +
                  "a.title,\n" +
                  "a.content,\n" +
                  "a.browse_count,\n" +
                  "a.publish_date,\n" +
                  "a.publish_real_name,\n" +
                  "a.user_id,\n" +
                  "(select count(f1.u_id) from favorite f1 where f1.a_id=a.id) as collectNum\n" +
                  "from article a \n" +
                  "left join favorite f on f.u_id=#{uId} \n"+
                  "where a.id=f.a_id ");
       if (map.containsKey("value")&&!StringUtils.isEmpty(map.get("value"))){
            sb.append("and (a.title like concat('%',#{value},'%'))");
        }
        return sb.toString();
    }
}
